<div class="modal-content">
  <div class="modal-header">
    <h6 class="modal-title text-purple">附件上传</h6>
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
  </div>
  <div class="modal-body py-4 text-center">
  {if function_exists('attachmentSave')}
    <form class="w-75 mx-auto py-3">
      <div class="input-group input-group-sm">
        <div class="input-group-prepend">
          <span class="input-group-text">所需积分</span>
        </div>
        <input class="form-control text-center" type="text" name="markDownScore" id="markDownScore" value="0" autocomplete="off" required>
        <div class="input-group-append">
           <button class="btn btn-purple markDownUpload" type="button" style="border-top-right-radius: .2rem;border-bottom-right-radius: .2rem;">
            <i class="fa fa-upload"></i> {:lang('upload')}
          </button>
        </div>
      </div>
    </form>
  {else/}
  <button class="btn btn-purple markDownUpload" type="button">
    <i class="fa fa-upload"></i> {:lang('upload')}
  </button>
  {/if}
  </div>
</div>
<script>
$(function() {
    daicuo.upload.init({
        url: '{$path_upload}',
        element: '.markDownUpload',
        container: 'editorUpload',
        multiple: true,
        multipart_params: {score: $('#markDownScore').val()},
        maxSize: "{$Think.config.common.upload_max_size|default='5mb'}",
        mimeTypes: [{ extensions: "{$Think.config.common.upload_file_ext|default='.zip'}" }],
        onInit: function(up){
            $(document).on('change', '#markDownScore', function(){
                up.setOption("multipart_params", {
                  score : $(this).val()
                })
            });
        },
        onError: function(up, data){
            daicuo.bootstrap.dialog(data.msg);
        },
        onSuccess: function(up, file){
            $('.dc-modal .modal-dialog').html(false);
            $('.dc-modal').modal('hide');
            //文件名
            if(file.responseTp.data.score){
                var fileName = file.responseTp.data.old_name + '（需要'+file.responseTp.data.score+'个积分）';
            }else{
                var fileName = file.responseTp.data.old_name;
            }
            //插入编辑器
            if(file.responseTp.data.urlId){
                $.fn.markdown.element.replaceSelection("\n"+'['+fileName+']('+file.responseTp.data.urlId+')');
            }else{
                $.fn.markdown.element.replaceSelection("\n"+'['+fileName+']('+file.responseTp.data.url+')');
            }
        }
    });
});
</script>